<template>
  <div class="login-container1">
    <el-form class="login-form" autoComplete="on" :model="loginForm" :rules="loginRules"  :inline="true" ref="loginForm" label-position="left" label-width="80px">
      <div class="login-logo">
          <img src="../../assets/images/loginlogo.png" class="imgS"/>
      </div>
      <div class="login-con">
        <!-- <div class="errInfo"><p class="setC" v-if="istrue">{{errorInfo}}，请再次尝试。</p></div> -->
        <div class="label1">初次登录，请重置密码</div>
        <el-form-item prop="passWord" label="新密码"  >
            <el-input class='wd230' v-model='loginForm.passWord' name="passWord" type="password"  autoComplete="on" placeholder="" size="mini" />
        </el-form-item>
        <el-form-item prop="repassWord" label="验证密码">
            <el-input class='wd230' name="repassWord" type="password" v-model='loginForm.repassWord' autoComplete="on" placeholder="" size="mini" />
        </el-form-item>
        <div class='tocenter'>
          <el-button type="info" size="mini"  @click="backlogin">取　消</el-button>
          <el-button type="primary" size="mini" @click="toSure" :loading='loading'>保　存</el-button>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    var oldpas2 = (rule, value, callback) => {
      var regx = /^[a-zA-Z0-9]{6,18}$/;
      if (!regx.test(value)) {
        callback(new Error("请输入6-18位数的新密码"));
      } else {
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入新密码"));
      } else {
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入新密码"));
      } else if (value !== this.loginForm.passWord) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      errorInfo:'',
      istrue:false,
      loginForm: {
        passWord:''
      },
      loginRules: {
        passWord: [
          {
            required: true,
            trigger: "blur",
            message: "请输入6-18位数的密码"
          },
          { validator: validatePass, trigger: "blur" },
          { validator: oldpas2, trigger: "blur" }
        ],
        repassWord: [
          { required: true, trigger: "blur", message: "请输入6-18位数的密码" },
          { validator: validatePass2, trigger: "blur" }
        ],
      },
      loading: false,
    };
  },
  mounted(){
    if(this.$route.params.tenantId){
      this.tenantId = this.$route.params.tenantId;
      this.userId = this.$route.params.userId;
      this.resetCode = this.$route.params.resetCode;
    }
  },
  methods: {
    toSure(){
      this.$refs['loginForm'].validate(valid => {
        if (valid) {
          this.loading = true;
          let params = {
            tenantId:this.tenantId,
            userId:this.userId,
            resetCode:this.resetCode,
            password : this.loginForm.passWord
          }
          this.post(params,'services/FirstLoginResetPassword').then(rs => {
            this.loading = false;
            if(rs.success){
              this.istrue = false;
              this.$alert('修改密码成功', '提示', {
                confirmButtonText: '确定',
                callback: () => {
                  this.$router.push({ path: "/login" });
                }
              });
            }else{
              this.errorInfo = rs.error.message;
              this.istrue = true;
            }
          })
        }else{
          console.log('error');
        }
      })
    },
    backlogin(){
      this.$router.push({path:'/login'})
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.ht28{
    height:28px;
}
.wd230{
  width:230px;
}
.wd250{
    width:250px;
}
.label1{
  min-height: 18px;
  line-height: 18px;
  margin:10px;
  text-align: center;
  color:#CF1322;
}
.tocenter{
  text-align: center;
  margin-top:10px;
}
.login-container1 {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: $bg;
  .login-form {
    position: absolute;
    left: 0;
    right: 0;
    width: 400px;
    height:297px;
    background: #FFFFFF;
    border-radius: 15px;
    top:50%;
    margin-top:-160px;
    left:50%;
    margin-left:-200px;
    .login-logo{
        height:92px;
        text-align: center;
        // background-color:#889aa4;
        border-top-left-radius: 15px;
        border-top-right-radius: 15px;
        border-bottom: 1px solid #CBD1D3;
        .imgS{
            width:200px;
            margin:20px;
        }
    }
    .login-con{
        padding:0 32px 40px 30px;
        .errInfo{
          min-height: 18px;
          line-height: 18px;
          width: 260px;
          margin:10px 0 13px 76px;
          .setC{
            font-size: 13px;
            color: #CF1322;
            margin:0;
          }
        }
        .time5{
            margin-left:76px;
            width:250px;
            line-height: 17px;
            height: 17px;
            margin-bottom: 25px;
        }
        .subBtn{
            margin:0 0 0 76px;
            .wd150{
                width: 150px;
            }
            .forgetPwd{
                font-size: 12px;
                color: #027DCA;
                margin-left:36px;
                cursor: pointer;
            }
        }
    }
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
}
</style>

